﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using PloobsEngine.Utils;

namespace PloobsEngine.Particle3D
{
    public class CircleOfFireEmiter : GeneralEmiter
    {
        public CircleOfFireEmiter(Vector3 pos)
        {
            particlesPos = pos;
        }

        private Vector3 particlesPos;

        #region IEmiter Members

        public override string[] ParticleSystemUsed()
        {
            return new string[] { "SmokePlumeParticleSystem",  "FireParticleSystem" };
        }


        /// <summary>
        /// Helper for updating the fire effect.
        /// </summary>
        void UpdateFire()
        {
            const int fireParticlesPerFrame = 20;

            // Create a number of fire particles, randomly positioned around a circle.
            for (int i = 0; i < fireParticlesPerFrame; i++)
            {
                ParticlesSystems["FireParticleSystem"].AddParticle(RandomPointOnCircle() + particlesPos, Vector3.Zero);
            }

            // Create one smoke particle per frmae, too.
            ParticlesSystems["SmokePlumeParticleSystem"].AddParticle(RandomPointOnCircle() + particlesPos, Vector3.Zero);
        }


        /// <summary>
        /// Helper used by the UpdateFire method. Chooses a random location
        /// around a circle, at which a fire particle will be created.
        /// </summary>
        Vector3 RandomPointOnCircle()
        {
            const float radius = 30;
            const float height = 40;

            double angle = StaticRandom.Random() * Math.PI * 2;

            float x = (float)Math.Cos(angle);
            float y = (float)Math.Sin(angle);

            return new Vector3(x * radius, y * radius + height, 0);
        }



        public bool isActive()
        {
            return true;
        }

        #endregion

        public override void UpdateEmiter(GameTime gt)
        {
            UpdateFire();
        }

    }
}
